<?php

class WorkerVerifyRequestService
{



    /*
     * 增加请求
     *
     */

    public static function addNewRequest($worker,$avatar,$idcard,$pic_idcard,$real_name,$type_id,$work_year,$price,$status)
    {
        $v_reqquest = new WorkerVerifyRequest();

        Util::initObjData($v_reqquest);

        $v_reqquest->worker_id = $worker->worker_id;
        $v_reqquest->avatar = $avatar;
        $v_reqquest->pic_idcard = $pic_idcard;
        $v_reqquest->real_name = $real_name;
        $v_reqquest->id_card = $idcard;
        $v_reqquest->status = $status;
        $v_reqquest->type_id = $type_id;
        $v_reqquest->work_year = $work_year;
        $v_reqquest->mobile = $worker->mobile;
        $v_reqquest->price = $price;


        $worktype = WorkerTypes::model()->findByPK($type_id);



        Util::checkExistAndNotDelete($worktype);

        $v_reqquest->type_name = $worktype->name;


        Util::saveObjData($v_reqquest);


        //log 增加

        WorkerVerifyRequestService::addRequestLog($v_reqquest);


    }

    /*
     * 增加请求log
     *
     */
    public static function addRequestLog($v_request)
    {
        $request_Log = new  WorkerVerifyRequestLog();

        Util::initObjData($request_Log);

        $request_Log->worker_id = $v_request->worker_id;
        $request_Log->avatar = $v_request->avatar;
        $request_Log->pic_idcard = $v_request->pic_idcard;
        $request_Log->real_name = $v_request->real_name;
        $request_Log->id_card = $v_request->id_card;
        $request_Log->status = $v_request->status;
        $request_Log->request_id = $v_request->request_id;

        $request_Log->type_id = $v_request->type_id;
        $request_Log->work_year = $v_request->work_year;
        $request_Log->type_name = $v_request->type_name;

        $request_Log->mobile = $v_request->mobile;
        $request_Log->reason = $v_request->reason;
        $request_Log->price = $v_request->price;


        if($request_Log->status == MsgConst::WORKER_VERIFY_STATUS_VERIFIED || $request_Log->status == MsgConst::WORKER_VERIFY_STATUS_DENIED)
        $request_Log->created_by = SessionService::getAdminUserName();

        Util::saveObjData($request_Log);


    }

    /*
     * 获取最新的一条请求
     *
     */
    public static function getRequestByWorkerid($worker_id)
    {
        $vrequest = WorkerVerifyRequest::model()->find("worker_id=:worker_id",array("worker_id"=>$worker_id));

        if(empty($vrequest)==true)
            throw new Exception("无该工人对应的审核请求");

        return $vrequest;
    }

    /*
     * 修改请求状态
     */
    public static function changeRequestStatus($request,$status,$reason)
    {
        $request->status = $status;
        $request->reason = $reason;
        Util::updateObjData($request);
        Util::saveObjData($request);

        //add log

        //log 增加

        WorkerVerifyRequestService::addRequestLog($request);

    }














}


?>